<?php
    $path = "../../";
    require_once($path."OpenSiteAdmin/scripts/classes/SecurityManager.php");
    require_once($path."OpenSiteAdmin/scripts/classes/Form.php");
    require_once($path."OpenSiteAdmin/scripts/classes/Fieldset.php");
    require_once($path."OpenSiteAdmin/scripts/classes/Field.php");
    require_once($path."OpenSiteAdmin/scripts/classes/RowManager.php");
	require_once($path."OpenSiteAdmin/scripts/classes/ListManager.php");

    require_once($path."header.php");

    $id = intval($_REQUEST["id"]);
    $securityManager = new SecurityManager("manageFruit");

    $form = new Form(Form::EDIT, $path."admin/");
    $fieldset = new Fieldset_Vertical($form->getFormType());
    $keyField = $fieldset->addField(new Hidden("ID", "", null, true, true));
    $linkField = $fieldset->addField(new Text("name", "Name", array("maxlength"=>30), true, true));
    $fieldset->addField(new TextArea("comments", "Comments", array("rows"=>4, "cols"=>30), true, false));
    $fieldset->addField(new Date("expires", "Expire Date", null, true, true));

    $row = new RowManager("fruit", $keyField->getName(), $id);
    $fieldset->addRowManager($row);
    $form->addFieldset($fieldset);
    $form->process();

    $deleteForm = new Form(Form::DELETE);
    $deleteFieldset = new Fieldset_Vertical($deleteForm->getFormType());
    $deleteFieldset->addField($keyField);
    $deleteFieldset->addRowManager($row);
    $deleteForm->addFieldset($deleteFieldset);
    $deleteForm->setSubmitText("Throw Away");
    $deleteForm->process();

    if(empty($_GET["id"])) {
        $list = new ListManager(false);
		$list->display($fieldset, $keyField, $linkField, $_SERVER["QUERY_STRING"]);
	} else {
        $form->display();
        $deleteForm->display();
	}

    require_once($path."footer.php");
?>